package com.efounder.form.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.efounder.form.model.CompanyModel;
import com.efounder.util.AppContext;

import java.util.ArrayList;

/**
 * Created by cherise on 2017/3/10.
 */

public class CheckTextView extends TextView {
    private Context mContext;
    private ArrayList<CompanyModel> listData;//新的数据
    private ArrayList<CompanyModel> selectData;//选中的数据

    public CheckTextView(Context context) {
        super(context);

        init(context);
    }

    public CheckTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);

    }

    public CheckTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public void init(Context context) {
        this.mContext = context;
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listData == null) {
                    return;
                }
                CheckBoxPopWindow popWindow = new CheckBoxPopWindow(AppContext.getCurrentActivity(), listData);
                popWindow.showAtLocation(v, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                popWindow.setSelectModelCallBack(new CheckBoxPopWindow.SelectModelCallBack() {
                    @Override
                    public void getSelectedModel(ArrayList<CompanyModel> list) {
                        selectData = list;
                        StringBuffer stringBuffer = new StringBuffer();
                        for (int i = 0; i < list.size(); i++) {
                            stringBuffer.append(list.get(i).getF_MC()).append(";");
                        }
                        if (stringBuffer.length() >= 1) {
                            stringBuffer.deleteCharAt(stringBuffer.length() - 1);
                        }
                        setText(stringBuffer.toString());
                    }
                });
            }
        });
    }

    public void setListData(ArrayList<CompanyModel> listData) {
        this.listData = listData;
    }

    public ArrayList<CompanyModel> getSelectData() {
        return selectData;
    }
}
